#ifndef TABLEMODEL_H
#define TABLEMODEL_H

#include <QAbstractTableModel>
#include <QVector>
#include <QMap>
#include <QVariant>
#include "configmanager.h"

class TableModel : public QAbstractTableModel
{
    Q_OBJECT
public:
    explicit TableModel(const QVector<ColumnConfig> &columns, QObject *parent = nullptr);

    int rowCount(const QModelIndex &parent = QModelIndex()) const override;
    int columnCount(const QModelIndex &parent = QModelIndex()) const override;
    QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
    QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
    Qt::ItemFlags flags(const QModelIndex &index) const override;

    void setData(const QVector<QMap<QString, QVariant>> &data);
    void sort(int column, Qt::SortOrder order = Qt::AscendingOrder) override;

    QVector<ColumnConfig> getColumns() const;
    QString getFieldName(int column) const;
    bool isColumnInteractive(int column) const;

private:
    QVector<ColumnConfig> m_columns;
    QVector<QMap<QString, QVariant>> m_data;
    QVector<int> m_sortedIndices;
};

#endif // TABLEMODEL_H
